#ifndef _GEN_PUZZLE_STATE_H_
#define _GEN_PUZZLE_STATE_H_

#include "bik_gameworld.h"

#include "input/keyboard.h"
#include "gameflow/ui_state.h"


namespace gameflow
{
	class UIPopup;
}

namespace LuaPlus
{
	class LuaState;
}


class GENGameState : public gameflow::UIState 
{
public:
						GENGameState(camera::FbCamera*	pCamera, const std::string& UI, const std::string& OnEnter, const std::string& OnExit);
	virtual				~GENGameState();

	/// called when the game flow manager transitions into this game state
	virtual	bool		OnEnter();

	/// called when the game flow manager transitions out of this game state
	virtual	bool		OnExit();

	/// render the help
	virtual	bool		PreRender();
	virtual	bool		PostRender();

	/// update the game
	virtual	bool		Tick(float dt);

	virtual void		KeyDown(input::Keyboard::KEY* pKey);
	virtual void		KeyPressed(input::Keyboard::KEY* pKey);
	virtual	void		MouseButtonPressed(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos);
	virtual	void		MouseButtonReleased(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos);
	virtual	void		MouseButtonDown(input::Mouse::BUTTON_STATE* pKey, const math::Vec2& Pos);
	virtual void		MouseMove(const math::Vec2& From, const math::Vec2& To);
	virtual void		MouseWheelMove(int WheelInfo, const math::Vec2& Pos);
	virtual void		MouseOnDrag(const math::Vec2& From, const math::Vec2& To) ;
	virtual void		MouseOnDrop(const math::Vec2& From, const math::Vec2& To) ;
	

	virtual void		LoseFocus();
	

	static GENGameState*	GetGame();
		

	void				Save(const std::string& File);

	static void			Register(LuaPlus::LuaState* _pScript);

	void				CachedLoad(const std::string& s);
	bool				HasCached() const { return !m_CachedLoad.empty(); };
	void				SetNextLevel(const std::string& Next) { m_NextLevel = Next; };
	const std::string&	GetNextLevel() const { return m_NextLevel; };
	void				ClearLevel();
	void				Pause();
	void				UnPause();

	void				OnLevelCompete();
	
	void					TickMe(gameflow::UIPopup* pPopup) { m_pActivePopup = pPopup; };
	void					FinishMe() { m_pActivePopup = NULL; };
	gameflow::UIPopup*		GetActivePopup() { return m_pActivePopup; };

protected:

	// UI Stuffs
	void DELEGATE_CALL	OnButtonPause(ui::UIWidget::WIDGET_EVENT Event, ui::UIWidget* pWidget);



	void				MouseScroll(float dt);
	void				LoadFromFile(const std::string& File);

	gameflow::GameTransition*	m_pFrom;
	gameflow::GameTransition*	m_pTo;

	int					GetHint(const std::string& Name);
	ui::UIWidget*		m_pUI;
	

	math::Vec2			m_FocusPoint;
	std::string			m_Name, m_Pwd;
	std::string			m_CachedLoad;
	

	bool				m_IsDebugging;
	std::string			m_NextLevel;
	bool				m_bIsPause;


	ui::UIWidget*		m_pUIPause;
	
	bool				m_IsConstantScreenShot;
	int					m_ConstantScreenShotIndex;
	bool				m_ToSkipConstantScreenShot;
	gameflow::UIPopup*		m_pActivePopup;

	float 				m_DelayFontRecreate;
	BIKGameWorld		m_GameWorld;

};


#endif //_GEN_PUZZLE_STATE_H_
